package com.example.demo4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.demo4.List_view_Adapter;
import com.example.demo4.Mode_v;
import com.example.demo4.R;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ListView listview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        function();
    }

    private void initView() {
        listview=findViewById(R.id.list_view);
    }
    private void function() {
        final List<Mode_v> list=new ArrayList<>();
        for(int i=0;i<4;i++)
        {
            list.add(new Mode_v(R.mipmap.data1,"Bak","好消息，明天休息一天","晚上11.05"));
            list.add(new Mode_v(R.mipmap.data2,"未来可期","继续努力吧！","上午12.45"));
            list.add(new Mode_v(R.mipmap.data3,"沐雨橙风","你好，在吗，在吗！","下午13.10"));
            list.add(new Mode_v(R.mipmap.data4,"朋友","[语言]","昨天"));
            list.add(new Mode_v(R.mipmap.data5,"家人","[视频通话]","周一"));
        }
        List_view_Adapter adapter=new List_view_Adapter(MainActivity.this,R.layout.mode_view,list);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Mode_v data= list.get(i);
                Toast.makeText(MainActivity.this, "你点击了"+data.getTitle(), Toast.LENGTH_SHORT).show();
            }
        });

    }


}
